#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 2e5+10;

int n,k,mod;
ll sum[N],inv[N];
map<int,int> m;
map<int,int> :: iterator it,it1;
ll ans;

ll qp(ll x,int t){ll res=1;for(;t;t>>=1,x=x*x%mod)if(t&1)res=res*x%mod;return res;}

void divide(int l,int r,int k){
	if(l == r || k <= 1){m[r-l+1]++;return;}
	int mid = l + r >> 1; divide(l,mid,k-1); divide(mid+1,r,k-1);
}

ll calc(int x,int y){
	ll res = 1ll * x * y % mod;
	for(int i = 1;i <= x;i++) res = (res - 2 * sum[i+y] + 2 * sum[i] + mod) % mod;
	return (res+mod)%mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in,mod = in;
	for(int i = 1;i < N;i++) inv[i] = qp(i,mod-2);
	for(int i = 1;i < N;i++) sum[i] = (sum[i-1] + inv[i]) % mod;
	divide(1,n,k);
	for(it = m.begin();it != m.end();it++){
		ll x = it->fi, s = it->se;
		ans = (ans + x * (x - 1) % mod * inv[2] % mod * inv[2] % mod * s % mod) % mod;
		ans = (ans + s * (s - 1) % mod * inv[2] % mod * inv[2] % mod * calc(x,x) % mod) % mod;
	}
	for(it = m.begin();it != m.end();it++)
		for(it1 = m.begin();it1 != m.end();it1++){
			ll x1 = it->fi,s1 = it->se,x2 = it1->fi,s2 = it1->se;
			if(x1 >= x2) continue;
			ans = (ans + s1 * s2 % mod * inv[2] % mod * calc(x1,x2) % mod) % mod;
		}
	printf("%lld\n",ans);
	return 0;
}

